home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-06-18 | 6.1 KB | 276 lines | [TEXT/MSET] |
- \ Microsoft Word 4.0 documents
- \ Access to Microsoft Word documents. MRH Oct 86
- \ March 87 - extensively revised. Input of formats implemented.
- \ April 87 - handling of MW 3.0 docs included
- \ - package broken into several files.
- \ March 88 - Reorganized into modules.
-
- need byteString
- need stringarray
- need file+
- need info_run
-
-
- \ The following items are used by the application.
-
- 'type WDBN constant MWDOC_TYPE
- 'type WORD constant MW1_CREATOR
- 'type MSWD constant MW3_CREATOR
-
-
- false value TEXT_ONLY? \ Set this TRUE if you only want text
- \ in or out.
- false value FACING_PAGES?
-
-
- \ The application must set up these strings. This package puts
- \ info into them or takes it from them, as the case may be.
-
- info_run FMT_RUN
- info_run PARA_RUN
-
- 14 setInfoSize: fmt_run
- 2 setInfoSize: para_run
-
-
- bytestring TEXT \ Ascii text of the document
- bytestring STYLE_NAMES \ Style names
-
-
- \ =================================
-
- \ Constants, values etc.
-
- \ =================================
-
- type{ MWtext MW1 MW3 MW4 } \ Add more as necessary!!
-
- 0 value MWTYPE \ Type of current document
-
-
- 3 constant DFLT_FONT# \ We use Geneva as the default font
- $ 100 constant HDR_LEN \ For Word 3 - redefined in MW1mod
-
- $ C constant SECT \ Code for a section break
-
- $ F constant FTN_MARK \ Footnote mark
- $ 16 constant HF_END_MARK \ Only in text proper
- $ 17 constant SECT_END_MARK \ NOT in text proper - HF area only
- $ 18 constant TEXT_END_MARK \ We mark the end of the text proper
- \ with this. We hope the user
- \ doesn't put any $18s in!!
-
- \ We also use: 10 even header 11 odd header 12 even footer 13 odd footer
- \ 14 first header 15 first footer.
-
- objPtr TheFCB class_is file+
-
- 0 value #STYLES \ Number of styles in style sheet.
- 0 value MEM_NEEDED
- 0 value BLK#
- 0 value #ENTRIES
- 0 value #BLKS
- 0 value #FMT_BLKS
- 0 value #PARA_BLKS
- 0 value #LEVELS
- 0 value SAVE_OFFS
- 0 value PARA_OFFS
- 0 value REAL_TEXT_LEN
- 0 value FTN_LEN
- 0 value TOTAL_TEXT_LEN
- 0 value TEXT&HF_LEN
- 0 value #INSRTD
- 0 value UNMPD_OLD
- 0 value UNMPD_NEW
- false value FAST?
- false value GHF?
- false value MW4? \ True if this is a Word 4 document
-
- false value WRONGTYPE?
- false value MYSTERY?
- 0 value UNPROCESSED_CODE
-
-
- bytestring BUF
- bytestring BUF_TMP
- bytestring BUF_OFFSETS
- bytestring HF_OFFSETS \ String of offsets of hdrs and footers
- bytestring SECT_OFFSETS \ String of section offset info
- bytestring SECT_STR \ String of strange section info
- bytestring FTN_MARKERS \ String of footnote marker offsets in text
- bytestring FTN_OFFSETS \ String of offsets to the footnotes
- info_run SRC \ Temp substring for sundry sources
- info_run DST \ Likewise for destinations
- bytestring TMP \ Used for many things
-
- bytestring TheFile \ Holds input MW3/4 doc before fixup
-
- bytestring FMT_BLK#S
- bytestring PARA_BLK#S
- bytestring BLK#S
- bytestring PARA_TMP
-
- bytestring CHANGES \ These 5 strings are used in handling
- bytestring FMT_OV_STR \ "Fast Saved" documents.
- bytestring PARA_OV_STR
- bytestring SECT_OV_STR
- info_run FMT_OV_RUN
-
- infoSize: fmt_run setInfoSize: fmt_ov_run
-
- 4 stringarray HF_ARRAY \ Used in handling headers and footers
-
- 10 constant FMT_LEN
-
- variable FMT fmt_len 4 + allot \ Allow a safety margin
-
- trtbl UTTBL \ Utility translate table - various uses
-
-
- \ ========== Imports ==========
-
- forward STR_OUT
-
- from MWUTMOD import{ TRIM_FMT_RUN ?KEEP_PARA NEXT_PARA TRIM_PARA_RUN }
-
- from MW1MOD import{ SETUP_INP1 INPUT_FILE1 WINDUP_INP1 SEND1 }
-
- from G&HFMOD import{ MARK_SP SPEC_IN MARK_FTN
- MARK_HFS UPDATE_HFS FIXUP_FTN FIXUP_HFS
- HANDLE_SPEC GHF_FORMATS_OUT }
-
- from MW3/4MOD import{ GET_STYLE_NAME GET_STYLE# NEED_LEVEL (STR_OUT)
- SETUP_INP3 SETUP_INP4
- INPUT_FILE3 INPUT_FILE4
- FIXIT3 FIXIT4
- WINDUP_INP3 WINDUP_INP4
- SEND3 }
-
- :f STR_OUT (str_out) ;f
-
- \ =============================
-
- :class MWDOC super( object )
-
- int TEXT?
- int CONTINUE?
-
- :m CHK_MEM:
- mem_needed 10000 + free >
- IF ( short of mem )
- mem_needed 1000 +
- freeBlk \ purges mem
- > \ Out of mem?
- IF \ Aarrggghh! Yes!
- close: theFcb drop
- noMem
- false put: continue?
- THEN
- THEN ;m
-
-
- :m BRING: \ ( fcb -- )
- -> theFcb pause
- 0 -> #levels clear: text?
- clear: text clear: fmt_run clear: para_run
- clear: style_names
- getFileInfo: theFcb OK?
- size: theFcb -> mem_needed
- true put: continue?
- getType: theFcb 'type TEXT =
- IF
- MWtext -> MWtype
- ELSE
- false -> mw4?
- getCreator: theFcb MW1_creator =
- IF
- MW1
- ELSE
- pad 2 read: theFcb OK?
- pad w@
- CASE[ $ FE34 ]=> MW3
- [ $ FE37 ]=> MW4 true -> mw4?
- DEFAULT=> true -> wrongType? MWtext
- ]CASE
- THEN
- -> MWtype
- THEN
- MWtype
- SELECT{
- MWtext IS{
- true put: text?
- chk_mem: self get: continue?
- IF
- theFcb readAll: text
- THEN }END
-
- MW1 IS{ setup_inp1
- chk_mem: self get: continue?
- IF input_file1 THEN }END
-
- MW3 IS{ setup_inp3
- chk_mem: self get: continue?
- IF input_file3 THEN }END
-
- MW4 IS{ setup_inp4
- chk_mem: self get: continue?
- IF input_file4 THEN }END
- default{
- }SELECT ;m
-
-
-
- :m FIXUP: { flg -- flg' }
- \ Fixes up everything after reading the
- \ file in. flg is true if the caller wants us to continue.
- \ We do things this way as when we read in the file we
- \ opened all sorts of strings which need to be released
- \ even if the input operation is to be aborted. We return
- \ flg' which is true if everything is OK.
-
- pause
- get: text? IF true EXIT THEN
- \ watchcurs
- get: continue? flg and dup ( do we continue? )
- MWtype
- SELECT{
- MWtext IS{ }END
- MW1 IS{ drop }END
- MW3 IS{ IF fixit3 THEN windup_inp3 }END
- MW4 IS{ IF fixit4 THEN windup_inp4 }END
-
- default{
- }SELECT
- \ arrowcurs
- pause ;m
-
-
- :m SEND: { fcb -- }
- pause
- false -> mw4? \ We're not writing in MW4 format yet
- text_only?
- IF
- reset: text text_end_mark chsearch: text drop
- len: text setsize: text
- fcb $write: text EXIT
- THEN
- fcb getFileInfo: file+ OK? fcb getCreator: file+
- MW1_creator = IF MW1 ELSE MW3 THEN
- -> MWtype
- fcb
- MWtype
- SELECT{
- MW1 IS{ send1 }END
- MW3 IS{ send3 }END
- default{
- }SELECT ;m
-
- ;class
-
- MWdoc TheDoc
-
- compile: MWutMod
- compile: MW1mod
- compile: g&hfMod
- compile: MW3/4mod
-